package com.mq.utils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;



import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * rabbitmq连接工具类
 * @author Administrator
 *
 */
public class ConnectionUtils {
	
	private static final String mq_host = "127.0.0.1";
	private static final int mq_port = 5672;
	
	public static Connection getConnection() throws IOException, TimeoutException {
		//定义连接工厂
		ConnectionFactory factory = new ConnectionFactory();
		//设置服务器地址
		factory.setHost(mq_host);
		//设置端口
		factory.setPort(mq_port);  //amqp 协议端口，类似mysql端口3306
		//设置账号、密码、vhost（类似db，mq数据仓库）
		factory.setVirtualHost("/vhost_zxl");
		factory.setUsername("user_zxl");
		factory.setPassword("123");
		
		//通过工厂连接
		Connection connection =  (Connection) factory.newConnection();
		return connection;
	}
}
